<?php
namespace app\admin\controller;

use app\admin\my\MyPage;
use app\admin\my\MyConfig;

class Feed extends Base {
   
	private $we_type = [ '订阅号', '认证订阅号', '服务号','认证服务号' ];
    private $sex = ['未知','男','女'];
    private $qrcode_type=['临时二维码','数值型永久二维码','字符型永久二维码'];

    public function feed() {
		$my = new MyPage();
	    $my ->title("反馈项目")
		    ->suggest("可以是内部项目也可以是外部项目")
		    ->buttonNew("feedEdit")
		    ->setDb('feed')
		    ->keyId()
		   
		    ->keyJoin('shopid', '分店', 'id', 'title', 'admin_shop', 'printer/index/index')
		    ->keyJoin('appid', '微信', 'appid', 'title', 'We')
		    ->keyText('feed1', '反馈项目1')
		    ->keyText('feed2', '反馈项目2')
		    ->keyText('feed3', '反馈项目3')
		    
		    ->keyUpdateTime()

		    ->actionEdit()
		    ->actionStatus()
		    ->map('title', '名称', '微信公众号昵称')
		    ->map('wechat_type', '类型', '微信公众号类型', 'select', $this->we_type)
		    ->mapStatus();

    	if ( request()->isAjax() ) {
    		$data=my_data($my,'Printer');
            foreach ($data['rows'] as $key => &$value) {
           
    			if (cache('printer_online_'.$value['shopid'])==1){
    			 $value['online']='在线';
    			}else{
    			 $value['online']='离线';	
    			}

    		}

    		return $data; 
	    } else {
		    return $my->fetch();
	    }
    }



    public function printerEdit($id=0) {
		

		if ( request()->isPost() ) { 

			$res = model('printer/printer')->editData();
			if ($res>0) $this->success('更新成功','printer');
			$this->error('更新失败');
		} else {
			$shops=my_select('AdminShop');
			$Wes=my_select('We','appid','title');
			$data=my_edit('printer/printer',$id);

			$my = new MyConfig();
			return  $my->title("编辑打印机")->keyId()
					    ->keyText('title', '名称')
					    ->keySelect('shopid','分店','','',$shops)
					    ->keySelect('appid','微信','','',$Wes)
					    ->keyImage('qrcode', '二维码')
					    ->keyText('free', '免费')
					   
					    ->keyText('word_ad', '文字广告')
					    ->keyText('printing_ad', '打印中广告')
					    ->keyText('success_ad', '成功广告')
					    ->keyText('pay_ad', '支付广告')

					    ->keySelect('qrcode_ad','二维码广告','','',['关闭','开启'])

					    ->group( '基本', 'fa-cog', 'id,title,shopid,appid,qrcode')
					    ->group( '广告', 'fa-wechat', 'word_ad,printing_ad,success_ad,pay_ad')
					    ->group( '设置', 'fa-wechat', 'free,password')
					    ->buttonSubmit()->buttonBack()
                        ->data($data)->fetch();
		}
	}

	 public function fans() {
		$my = new MyPage();
	   
	    $my ->title("打印会员管理")
		    ->suggest("每一台打印机都是吸粉神器")
		    ->buttonNew("printerEdit")
		    ->setDb('PrinterFans')
		    ->keyId()
		    ->keyText('nickname', '昵称')
		    ->keyText('balance', '余额')
		   
		    ->keyText('times', '打印次数')
		    ->keyText('pay', '支付次数')
		   
		    ->actionEdit()
		    ->actionStatus()
		    ->map('nickname', '名称')
		   
		    ->mapStatus();

    	if ( request()->isAjax() ) {
    		return my_data($my,'PrinterFans');
	    } else {
		    return $my->fetch();
	    }
    }



    public function fansEdit($id=0) {
		

		if ( request()->isPost() ) { 

			$res = model('printer/PrinterFans')->editData();
			if ($res>0) $this->success('更新成功','fans');
			$this->error('更新失败');
		} else {
			
			$data=my_edit('printer/PrinterFans',$id);

			$my = new MyConfig();
			return  $my->title("编辑会员")->keyId()
					    ->keyText('nickname', '昵称')
					    ->keyText('balance', '余额')
					   
					    
					    ->buttonSubmit()->buttonBack()
                        ->data($data)->fetch();
		}
	}


	public function pic() {
		$my = new MyPage();
	   
	    $my ->title("打印记录")
		    ->suggest("这里记录每一次打印")
		    ->buttonNew("picEdit")
		    ->setDb('PrinterPic')
		    ->keyId()
		    ->keyText('nickname', '昵称')
		    ->keyJoin('shopid', '分店', 'id', 'title', 'admin_shop')
		    ->keyJoin('printer', '打印机', 'id', 'title', 'printer')
		    
		    // ->keyText('url', '图片')
		   
		    ->keyMap('style', '类型',['竖片','横片'])
		    ->keyText('width', 'width')
		    ->keyText('height', 'height')
		    ->keyText('type', 'type')
		    ->keyText('P_ID', 'P_ID')
		    ->actionEdit()
		    ->actionStatus()
		    ->map('title', '名称')
		    ->mapStatus();

    	if ( request()->isAjax() ) {
    		return my_data($my,'PrinterPic');
	    } else {
		    return $my->fetch();
	    }
    }



	public function pay() {
		$my = new MyPage();
	   
	    $my ->title("打印机管理")
		    ->suggest("每一台打印机都是吸粉神器")
		    ->buttonNew("payEdit")
		    ->setDb('PrinterPay')
		    ->keyId()
		    ->keyText('nickname', '昵称')
		    ->keyJoin('shopid', '分店', 'id', 'title', 'admin_shop')
		    ->keyJoin('appid', '微信', 'appid', 'title', 'we')
		    
		    ->keyText('um', '充值')
		    ->keyText('price', '充值金额')
		    ->keyText('balance', '余额')
		   
		    ->keyMap('pay_type','方式',['指令','微信支付'])


		   
		    ->actionEdit()
		    ->actionStatus()
		    ->map('nickname', '昵称')
		    ->mapStatus();

    	if ( request()->isAjax() ) {
    		return my_data($my,'PrinterPay');
	    } else {
		    return $my->fetch();
	    }
    }


}